﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

using Daybreak.Core.Rendering.Pipeline;

namespace Daybreak.Core.SceneGraph
{
    /// <summary>
    /// Base class for all internal nodes in the scene graph. 
    /// </summary>
    public abstract class Node : IAsset
    {
        public delegate void UpdateHandler(Node node, NodeVisitor updater, float deltaTime);

        /// <summary>
        /// Node name (should be unique)
        /// </summary>
        public string Name;
        public event UpdateHandler OnUpdate;

        public Node() { }

        public virtual void Accept(NodeVisitor visitor)
        {

        }

        public virtual void Accept(Streamer streamer)
        {
        }

        public virtual void Initialize() { }

        public virtual void UpdateFrameData(Pipes.FrameContext frameData, ref RenderArgs args) { }

        /// <summary>
        /// Update node
        /// </summary>
        /// <param name="updater">updater visitor instance</param>
        /// <param name="deltaTime">time (seconds) elapsed since last update</param>
        public virtual void Update(NodeVisitor updater, float deltaTime)
        {
            if (OnUpdate != null)
                OnUpdate(this, updater, deltaTime);
        }

        public virtual void ComputeBound(ref BoundingBox result) { }

        public virtual void LocalToWorld(ref Matrix result) { }

        public virtual void WorldToLocal(ref Matrix result) { }

        public virtual IAsset Clone()
        {
            return this.MemberwiseClone() as IAsset;
        }


    }
}
